<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>个人信息 - 光年(Light Year Admin V4)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,LightYearAdmin,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="Light Year Admin V4是一个后台管理系统的HTML模板，基于Bootstrap v4.4.1。">
<meta name="author" content="yinqi">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/layui.css" rel="stylesheet">
<link href="/static/css/materialdesignicons.min.css" rel="stylesheet">
<link href="/static/css/style.min.css" rel="stylesheet">
  <style>
    .img-avatar{
      width: 100px;
      height: 100px;
    }
  </style>
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <div class="media">
            <img src="{$user['avatar']? $user['avatar'] :'/static/images/users/avatar.jpg'}" alt="..." class="img-avatar mr-3">
            <div class="media-body">
              <button class="btn btn-default" id="change_avatar">修改头像</button>
            </div>
          </div>
          <hr>
          <form method="post" action="" class="site-form">
            <div class="form-group">
              <label for="username">用户名</label>
              <input type="text" class="form-control" name="username" id="username" placeholder="输入用户名" value="{$user['username']}" >
            </div>
            <div class="form-group">
              <label for="realname">姓名</label>
              <input type="text" class="form-control" name="realname" id="realname" placeholder="输入姓名" value="{$user['realname']}">
            </div>
            <div class="form-group">
              <label for="email">邮箱</label>
              <input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelp" placeholder="请输入正确的邮箱地址" value="{$user['email']}">
              <small id="emailHelp" class="form-text text-muted">请保证您填写的邮箱地址是正确的。</small>
            </div>
            <div class="form-group">
              <label for="remark">简介</label>
              <textarea class="form-control" name="remark" id="remark" rows="3">{$user['remark']}</textarea>
            </div>
            <button type="submit" class="btn btn-primary">保存</button>
          </form>
 
        </div>
      </div>
    </div>
    
  </div>
  
</div>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/popper.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/main.min.js"></script>
<script type="text/javascript" src="/static/layui.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/js/msg.js"></script>
<script>
  layui.use('upload', function(){
    var upload = layui.upload;

    //执行实例
    var uploadInst = upload.render({
      elem: '#change_avatar' //绑定元素
      ,url: '/index/common/upload' //上传接口
      ,field:"image"
      ,done: function(res){
        if(res.code){
          $.ajax({
            url:"/index/user/avatar",
            data:{
              id:{$user['id']},
              avatar:res.data.url
            },
            method:"POST",
            dataType:"json",
            success:function (avatarRes){
              if(avatarRes.code){
                msgShow.success("头像修改成功")
                location.reload();
              }else {
                msgShow.error("头像修改失败")
              }
            }
          })
        }
      }
      ,error: function(){
        //请求异常回调
      }
    });
  });
</script>
</body>
</html>